package com.ygsoft.tianlu_mall.service.impl;

import com.ygsoft.tianlu_mall.mapper.CartMapper;
import com.ygsoft.tianlu_mall.mapper.CollectMapper;
import com.ygsoft.tianlu_mall.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@Service
public class CartServiceImpl implements CartService {

    @Autowired
    CartMapper cartMapper;

    @Override
    public List<HashMap<String,Object>> checkGoodsInCart(int user_id, int goods_id) {
        HashMap<String,Object> map = new HashMap<>();
        map.put("user_id",user_id);
        map.put("goods_id",goods_id);
        return cartMapper.checkGoodsInCart(map);
    }

    @Override
    public List<HashMap<String,Object>> checkGoodsNotMine(int user_id, int goods_id) {
        HashMap<String,Object> map = new HashMap<>();
        map.put("user_id",user_id);
        map.put("goods_id",goods_id);
        return cartMapper.checkGoodsNotMine(map);
    }

    @Override
    public void addGoodsToCart(int user_id, int goods_id) {
        int shop_id = cartMapper.getShopIdByGoodsId(goods_id);
        HashMap<String,Object> map = new HashMap<>();
        map.put("user_id",user_id);
        map.put("goods_id",goods_id);
        map.put("shop_id",shop_id);
        cartMapper.addGoodsToCart(map);
    }

    @Override
    public void deleteGoodsFromCart(int user_id, int goods_id) {
        HashMap<String,Object> map = new HashMap<>();
        map.put("user_id",user_id);
        map.put("goods_id",goods_id);
        cartMapper.deleteGoodsFromCart(map);
    }

    @Override
    public HashMap<String, Object> getGoodsInfoFromCart(int user_id) {
        List<HashMap<String, Object>> shopList = cartMapper.getShopInfoFromCart(user_id);
        List<HashMap<String, Object>> goodsList = cartMapper.getGoodsInfoFromCart(user_id);
        List<HashMap<String, Object>> propertyAndValueList = cartMapper.getPropertyAndValueFromCart(user_id);
        HashMap<String,Object> goodsInfoFromCart = new HashMap<>();
        goodsInfoFromCart.put("shopList",shopList);
        goodsInfoFromCart.put("goodsList",goodsList);
        goodsInfoFromCart.put("propertyAndValueList",propertyAndValueList);
        return goodsInfoFromCart;
    }

    @Override
    public void clearFailedGoods(int user_id, int goods_id) {
        HashMap<String,Object> map = new HashMap<>();
        map.put("user_id",user_id);
        map.put("goods_id",goods_id);
        cartMapper.clearFailedGoods(map);
    }

    @Override
    public int getCartCount(int user_id) {
        return cartMapper.getCartCount(user_id);
    }
}
